# require "#{RAILS_ROOT}/app/models/item"

require "#{RAILS_ROOT}/app/classes/cat/cat_model"
require "#{RAILS_ROOT}/app/classes/irt/irt_item"

#* cat_item.rb
#* Copyright (C) 2010  Embian Inc.
#
#  This program is free software: you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation, either version 3 of the License, or 
#  (at your option) any later version.
#  
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#  
#  You should have received a copy of the GNU General Public License
#  along with This program.  If not, see <http://www.gnu.org/licenses/>.
#  
#* Extends IRTItem class
#* Author: KyoungMo Yang(E-mail : mo@embian.com)
#* Modified: 2010-12-01
#* References: IRTItem, CATModel
class CATItem < IRTItem
  
  #* Functionailities
  # * Calculates information(I)
  #* Parameters 
  # * [new_id] : item id 
  # * [q_no] : question No.
  #* Return
  # * An instance of IRTItem class
  #* Note
  # * Formula : I(Θ) = a^2*P(Θ)Q(Θ)
  #             P(Θ) = c + (1-c) * (1 / (1 + exp(-1.7*a*(Θ-b))))
  #             Q(Θ) = 1 - P(Θ)
  def I_of(theta, cat_model)
    raise "Invalid Paramter : 'cat_model' is an instance of CATModel" unless cat_model.is_a? CATModel
    p = cat_model.fun_logistic(theta, @irt_a, @irt_b, @irt_c)
    return @irt_a * @irt_a * p * (1.0 -p)
  end
  
  #* Functionailities
  # * Do not support to change ID of item
  #* Parameters 
  # * N/A
  #* Return
  # * N/A
  #* Note
  #* Raise NotImplementedError
  def iid=(value)
    raise NotImplementedError
  end
  
  #* Functionailities
  # * Do not support to change discriment param of item
  #* Parameters 
  # * N/A
  #* Return
  # * N/A
  #* Note
  #* Raise NotImplementedError
  def irt_a=(value)
    raise NotImplementedError
  end
  
  #* Functionailities
  # * Do not support to change difficulty param of item
  #* Parameters 
  # * N/A
  #* Return
  # * N/A
  #* Note
  #* Raise NotImplementedError
  def irt_b=(value)
    raise NotImplementedError
  end
  
  #* Functionailities
  # * Do not support to change guessing param of item
  #* Parameters 
  # * N/A
  #* Return
  # * N/A
  #* Note
  #* Raise NotImplementedError
  def irt_c=(value)
    raise NotImplementedError
  end
  
  #* Functionailities
  # * Override Object#to_s
  #* Parameters 
  # * N/A
  #* Return
  # * N/A
  #* Note
  #* N/A
  def to_s
    return "#{no} : discriments=[#{("%.3f" % irt_a)}], difficulty=[#{("%.3f" % irt_b)}], guessing=[#{("%.3f" % irt_c)}]"
  end
end